import store from '@/store'

// 字符验证权限
export function checkPermission(value) {
    // if (policy === '*') return true
    // const centralConfig = store.getters.centralConfig
    // if (centralConfig && centralConfig.auth.grantedPolicies[policy]) {
    //     return true
    // } else if (policy.includes('||')) {
    //     const arr = policy.split('||')
    //     for (let i = 0; i < arr.length; i++) {
    //         if (centralConfig.auth.grantedPolicies[arr[i]]) {
    //             return true
    //         }
    //     }
    // } else {
    //     return false
    // }
    if (value && value instanceof Array && value.length > 0) {
        const permissions = store.getters && store.getters.permissions
        const permissionDatas = value
        // const all_permission = ("*.*.*" || "*:*:*");
    
        const hasPermission = permissions.some(permission => {
          return ("*:*:*" == permission||"*.*.*" ==permission )|| permissionDatas.includes(permission)
        })
    
        if (!hasPermission) {
          return false
        }
        return true
      } else {
        console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
        return false
      }
}

